package com.ohy.tencent.util;

import java.util.HashMap;

public class AjaxResult extends HashMap<String, Object> {
    private int code;
    private String msg;
    private Object data;

    public AjaxResult() {
    }

    public AjaxResult(int code, String msg, Object data) {
        this.put("code", code);
        this.put("msg", msg);
        this.put("data", data);
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return this.data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static AjaxResult success() {
        AjaxResult json = new AjaxResult();
        json.put((String) "code", 200);
        json.put((String) "msg", "success");
        return json;
    }

    public static AjaxResult success(Object data) {
        AjaxResult json = new AjaxResult();
        json.put((String) "code", 200);
        json.put((String) "msg", "success");
        json.put("data", data);
        return json;
    }

    public static AjaxResult success(String msg) {
        AjaxResult json = new AjaxResult();
        json.put((String) "code", 200);
        json.put((String) "msg", msg);
        return json;
    }

    public static AjaxResult success(String msg, Object data) {
        AjaxResult json = new AjaxResult();
        json.put((String) "code", 200);
        json.put((String) "msg", msg);
        json.put("data", data);
        return json;
    }

    public static AjaxResult success(String msg, String data_name, Object data) {
        AjaxResult json = new AjaxResult();
        json.put((String) "code", 200);
        json.put((String) "msg", msg);
        json.put(data_name, data);
        return json;
    }

    public static AjaxResult error400(String msg) {
        AjaxResult json = new AjaxResult();
        json.put((String) "code", 400);
        json.put((String) "msg", msg);
        return json;
    }

    public static AjaxResult error500(String msg) {
        AjaxResult json = new AjaxResult();
        json.put((String) "code", 500);
        json.put((String) "msg", msg);
        return json;
    }

    public static AjaxResult error500() {
        AjaxResult json = new AjaxResult();
        json.put((String) "code", 500);
        json.put((String) "msg", "系统异常，联系管理员!");
        return json;
    }

    /**
     * 失败
     *
     * @param code
     * @param message
     * @return
     */
    public static AjaxResult error(String code, String message) {
        AjaxResult result = new AjaxResult();
        result.setCode(Integer.parseInt(code));
        result.setMsg(message);
        result.setData(null);
        return result;
    }

    @Override
    public AjaxResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }

}